package action;

import javax.servlet.http.Cookie;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import dao.ItemDAO;

import util.ActionForward;
import vo.Item;

public class ItemViewAction implements Action{

	@Override
	public ActionForward execute(HttpServletRequest request,
			HttpServletResponse response) throws Exception {
		int itemid=Integer.parseInt(request.getParameter("itemnumber"));
		
		ItemDAO dao = ItemDAO.getInstance();
		boolean result = dao.updateRecordCount(itemid);
		System.out.println("update....."+result);
		Item item=dao.getItem(itemid);
		//////오늘 본 상품의 띄우는 로직 :: Cookie생성해서 선택한 이미지들을 쿠키로 저장..1)
		//////클라이언트로 넘긴다. ItemListAction에 추가한다 ///////////////////////////////////////
		Cookie cookie = new Cookie("image"+itemid, item.getUrl());
		cookie.setMaxAge(24*60*60);
		response.addCookie(cookie);
		//////////////////////////////////////////////////////////////
		
		request.setAttribute("item", item);
		
		ActionForward forward = new ActionForward();
		forward.setUrl("itemView.jsp");
		
		return forward;
	}

}










